<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/util.js"></script>
    <style>
        .errorInfo{
            color: red;
            font-size: 12px;
        }
    </style>
    <script>
        async function add(){
                let info=await ajaxGet("/user/add"
                    ,{name:getObject("name").value,
                        pwd:getObject("pwd").value,sex:getObject("sex").value,
                        money:getObject("money").value,birthday:getObject("birthday").value});
                if (info=="ok"){
                    let  divArray=document.getElementsByClassName("errorInfo");
                    for (let i=0;i<divArray.length;i++){
                        divArray[i].innerHTML="";
                    }
                    let posPattern = /^\d+$/;
                    if (posPattern.test(getObject("money").value)){
                        getObject("moneyDiv").innerHTML=""
                        location.href="/html/index.html"
                    }else {
                        getObject("moneyDiv").innerHTML="工资输入错误"
                    }

                }else {
                    let  divArray=document.getElementsByClassName("errorInfo");
                    for (let i=0;i<divArray.length;i++){
                        divArray[i].innerHTML="";
                    }
                    for(let i=0;i<info.length;i++){
                        let obj=info[i];
                        console.log(obj.field+"Div"+"   "+i);
                        getObject(obj.field+"Div").innerHTML=obj.defaultMessage;
                    }
                    let posPattern = /^\d+$/;
                    if (posPattern.test(getObject("money").value)==false){
                        getObject("moneyDiv").innerHTML="工资输入错误"
                    }
                }

        }
    </script>
</head>
<body>
    <div id="nameDiv" class="errorInfo"></div>
    用户名:<input type="text" id="name"><br>
    <div id="pwdDiv" class="errorInfo"></div>
    密码:<input type="password" id="pwd"><br>
    性别：<input type="radio"  id="sex" value="男" checked>男
    <input type="radio"  id="sex" value="女">女<br>
    <div id="moneyDiv" class="errorInfo"></div>
    工资:<input type="text" id="money" onkeyup="this.value=this.value.replace(/\D/g,'')"><br>
    <div id="birthdayDiv" class="errorInfo"></div>
    生日:<input type="date" id="birthday"><br>
    <input type="button" value="提交注册" onclick="add()">
</body>
</html>